<div class="panel panel-default panel-intro">
    {:build_heading()}

    <div class="panel-body">
        <div id="myTabContent" class="tab-content">
            <div class="tab-pane fade active in" id="one">
                <div class="widget-body no-padding">
                    <div id="toolbar" class="toolbar">
                        {:build_toolbar('refresh,add,edit,del')}
                        <div class="dropdown btn-group">
                            <a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>
                            <ul class="dropdown-menu text-left" role="menu">
                                <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="type=inbound"><i class="fa fa-sign-in"></i> {:__('入库')}</a></li>
                                <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="type=outbound"><i class="fa fa-sign-out"></i> {:__('出库')}</a></li>
                                <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="type=check"><i class="fa fa-check-square-o"></i> {:__('盘点')}</a></li>
                            </ul>
                        </div>
                    </div>
                    <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
                           data-operate-edit="{:$auth->check('manufacture/stock/edit')}" 
                           data-operate-del="{:$auth->check('manufacture/stock/del')}" 
                           width="100%">
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    var Table = $("#table").bootstrapTable({
        url: 'manufacture/stock/index',
        pk: 'id',
        sortName: 'id',
        sortOrder: 'desc',
        search: true,
        commonSearch: true,
        columns: [
            [
                {checkbox: true},
                {field: 'id', title: __('Id'), sortable: true},
                {field: 'material.material_code', title: __('物料编码'), sortable: true},
                {field: 'material.material_name', title: __('物料名称'), sortable: true},
                {field: 'material.category.name', title: __('物料分类'), sortable: true},
                {field: 'warehouse.warehouse_name', title: __('仓库'), sortable: true},
                {field: 'quantity', title: __('库存数量'), sortable: true},
                {field: 'warning_status_text', title: __('库存状态'), formatter: function(value, row, index) {
                    var colors = {'normal': 'success', 'low': 'warning', 'high': 'info', 'empty': 'danger'};
                    return '<span class="label label-' + colors[row.warning_status] + '">' + value + '</span>';
                }},
                {field: 'updatetime', title: __('更新时间'), formatter: Table.api.formatter.datetime},
                {field: 'operate', title: __('操作'), table: Table, events: Table.api.events.operate, 
                 buttons: [
                     {
                         name: 'inbound',
                         text: __('入库'),
                         title: __('物料入库'),
                         classname: 'btn btn-xs btn-success btn-dialog',
                         icon: 'fa fa-sign-in',
                         url: 'manufacture/stock/inbound',
                         callback: function (data) {
                             // 入库回调
                         }
                     },
                     {
                         name: 'outbound',
                         text: __('出库'),
                         title: __('物料出库'),
                         classname: 'btn btn-xs btn-warning btn-dialog',
                         icon: 'fa fa-sign-out',
                         url: 'manufacture/stock/outbound',
                         callback: function (data) {
                             // 出库回调
                         }
                     }
                 ],
                 formatter: Table.api.formatter.operate}
            ]
        ]
    });
</script>
